package com.mapper;

import com.pojo.User_chen;
import com.pojo.Yuyue_lfy;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;


@Mapper
public interface Yuyue_lfyMapper {
    @Insert("insert into yuyue_lfy(yuyue_time,yuyue_uid,yuyue_type,yuyue_content) values(#{yuyueTime},#{yuyueUid}," +
            "#{yuyueType},#{yuyueContent})")
    int insertInfo(@Param("yuyueTime") Date yuyueTime, @Param("yuyueUid") Integer yuyueUid,
                   @Param("yuyueType") String yuyueType,@Param("yuyueContent")
                   String yuyueContent);

    @Select("select yuyue_lfy.* from yuyue_lfy left join user_chen on yuyue_uid=user_chen.id")
    @Results({
            @Result(property = "yuyueUid", column = "yuyue_uid"),
            @Result(property = "yuyueTime", column = "yuyue_time"),
            @Result(property = "yuyueType", column = "yuyue_type"),
            @Result(property = "yuyueContent", column = "yuyue_content"),
            @Result(property = "userChen", column = "yuyue_uid", one = @One(select = "com.mapper.Yuyue_lfyMapper" +
                    ".selectUserById",fetchType = FetchType.EAGER))
    })
    List<Yuyue_lfy> selectAll();

    @Select("select username from user_chen where id=#{id}")
    User_chen selectUserById(Integer id);

    @Delete("delete  from yuyue_lfy where yuyue_id=#{yuyueId}")
    Integer delete(@Param("yuyueId") Integer yuyueId);

    @Select("select yuyue_lfy.* from yuyue_lfy left join user_chen on yuyue_uid=user_chen.id where " +
            "yuyue_time=#{yuyueTime} and username like concat ('%',#{username},'%')")
    @Results({
            @Result(property = "yuyueUid", column = "yuyue_uid"),
            @Result(property = "yuyueTime", column = "yuyue_time"),
            @Result(property = "yuyueType", column = "yuyue_type"),
            @Result(property = "yuyueContent", column = "yuyue_content"),
            @Result(property = "userChen", column = "yuyue_uid", one = @One(select = "com.mapper.Yuyue_lfyMapper" +
                    ".selectUserById",fetchType = FetchType.EAGER))
    })
    List<Yuyue_lfy> searchTime(@Param("yuyueTime") Date yuyueTime, @Param("username") String username);

    @Update("update yuyue_lfy set yuyue_time=#{yuyueTime},yuyue_del=#{yuyueDel}, yuyue_type=#{yuyueType}," +
            "yuyue_content=#{yuyueContent} " +
            "where " +
            "yuyue_id=#{yuyueId}")
    int updateInfo(@Param("yuyueTime") Date yuyueTime, @Param("yuyueDel") Integer yuyueDel,
                   @Param("yuyueType") String yuyueType,@Param("yuyueContent") String yuyueContent,@Param("yuyueId") Integer yuyueId );

}
